//引入封装头信息和请求域名的axios对象
import http from "./http";
//引入请求的URL地址
import { filmListUri, 
  comingsoonListUri,
  detailUri,
  cinemaUri
} from "../config/uri";

//函数的方式将axios封装起来
//方法二
// export const filmListDate=(vm,url)=>{
//   return vm.$axios.get(url+'1')
//返回的是promise
// }

//方法三
// export function filmListDate(url){
//     return this.$axios.get(url+'1')
// }

/**
 * 标准注释
 * 获取正在热映分页数据
 * @param {int} page 页码数 默认1
 * @return promise对象
 * 数据存放这里的好处是
 * 1.避免视图层逻辑过重
 * 2.维护便捷
 * 此处也可称为数据层
 *
 */
export const filmListDate = (page = 1) => {
  return http.get(filmListUri + page);
};
/**
 * 即将上映
 * @param {*} page
 */
export const comingsoonListDate = async (page = 1) => {
  let ret = {};
  let res = JSON.parse(localStorage.getItem("comingsoon"));
  if (res) {
    ret ={...res}
  } else {
    ret = await http.get(comingsoonListUri + page);
    // console.log(ret)
    localStorage.setItem("comingsoon", JSON.stringify(ret));
  }
  return Promise.resolve(ret);

  
};

/**
 * 获取详情
 * @param {*} page 
 */
export const detailData = (id = 1) => {
  return http.get(detailUri + id,{
    headers:{
      "info":"info"
    }
  }
  );
};

/**
 * 影院信息
 */
export const cinemaData = () => {
  return http.get(cinemaUri,{
    headers:{
      "info":"cinema"
    }
  }
  );
};
